package com.wwg.reflect.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class HelloFuncImpl implements HelloFunc {

    @Override
    public void sayHi() {
        System.out.println("我是原始方法—————sayHi");
    }

    @Override
    public void playBasketBall() {
        System.out.println("我是原始方法————playBasketBall");
    }

    public static void main(String[] args) {
        // 原对象
        HelloFunc origin = new HelloFuncImpl();

        // 代理策略
        BeStronger beStrongBefore = new BeStronger() {

            @Override
            public void beStrong() {
                System.out.println("beStrong--before");
            }
        };
        BeStronger beStrongAfter = new BeStronger() {

            @Override
            public void beStrong() {
                System.out.println("beStrong--after");
            }
        };
        InvocationHandler handler1 = new MyInvocationHandler(origin,beStrongBefore,beStrongAfter);

        // 代理对象
        HelloFunc handler = (HelloFunc) Proxy.newProxyInstance(origin.getClass().getClassLoader(),
                origin.getClass().getInterfaces(), handler1);
        handler.sayHi();
        handler.playBasketBall();

    }

}
